package database;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @author Pasukaru
 * Class MysqlConnect
 * Connects to the Mysql Database
 */
public class MysqlConnect{
	
	/**
	 * Default Constructor
	 */
    public MysqlConnect() {}
    
    /**
     * Connect Method
     * Create the connection to the database
     * @return Connection conn
     */
	public Connection connect() {
	    System.out.println("Connection to Mysql Database ...");
	    Connection conn = null;
	    // Defines the url where the database is
	    String url = "jdbc:mysql://localhost:3306/";
	    // Defines the name of the database
	    String dbName = "DeVint";
	    // Defines the driver class name
	    String driver = "com.mysql.jdbc.Driver";
	    // Defines the username and password to access the database (might be changed)
	    String userName = "root"; 
	    String password = "root";
		try {
			// Instance the mysql driver
		    Class.forName(driver).newInstance();
		    // Create connection to the database at the url specified above
		    conn = DriverManager.getConnection(url+dbName,userName,password);
		    System.out.println("Database connected !");
		}catch (Exception e) {
			  e.printStackTrace();
		}
		return conn;
    }

}
